-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: prevent allow notifications prompt on rotation #12201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java
Outdated
Show resolved
Hide resolved
I posted some notes on the original issue: |
Okay here’s an answer by ChatGPT which I think corresponds exactly to what I figured out but in a pretty well-phrased manner: To check whether a user has explicitly denied a permission in an Android app (especially if they selected "Don't ask again"), you can use a combination of the Key Concepts:
Code Example (Kotlin):val permission = Manifest.permission.CAMERA
when {
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED -> {
// Permission granted
}
ActivityCompat.shouldShowRequestPermissionRationale(activity, permission) -> {
// Permission denied before, but "Don't ask again" NOT selected
// Show rationale to user
}
else -> {
// Permission denied before AND "Don't ask again" selected
// Or first-time request on some devices
}
} Interpreting
|
This seems to be the only reliable way of making sure we only ever bother the user once. If they accept, from then on the permission check will be successful. If they deny or swipe away, we never ask again at startup and the user has to manually change it in the settings or go to our settings and re-do the prompt by activating notifications.
b7e5637
to
d63db94
Compare
@Stypox I think I fixed it and implemented it correctly with the |
|
What is it?
Description of the changes in your PR
Add variable permissionStatus to check if the user has already granted or denied permission.
Before/After Screenshots/Screen Record
notificationfix-before.mp4
notificationfix-after.mp4
Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.
Due diligence